﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Toyger.Common.UI;
using Toyger.Common.Connections;

namespace Toyger.Common.PlugIn.SqlServer2005
{
    public partial class ConnEditor_Sql2005 : UserControl, IConnectionEditor
    {
        ConnectionObject cObj;
        public ConnEditor_Sql2005(ConnectionObject cObj)
        {
            this.cObj = cObj;
            if (!this.cObj.CustomerProperties.ContainsKey(SqlServer2005Prop.Default.PropLoginname))
            {
                this.cObj.CustomerProperties.Add(SqlServer2005Prop.Default.PropLoginname, String.Empty);
            }
            if (!this.cObj.CustomerProperties.ContainsKey(SqlServer2005Prop.Default.PropPassword))
            {
                this.cObj.CustomerProperties.Add(SqlServer2005Prop.Default.PropPassword, String.Empty);
            }

            InitializeComponent();
            tbName.Text = this.cObj.CustomerProperties[SqlServer2005Prop.Default.PropLoginname];
            tbPw.Text = this.cObj.CustomerProperties[SqlServer2005Prop.Default.PropLoginname];
        }

        #region IConnectionEditor Members

        public Control GetControl()
        {
            return this;
        }

        public void Save()
        {
            cObj.CustomerProperties[SqlServer2005Prop.Default.PropLoginname] = tbName.Text;
            cObj.CustomerProperties[SqlServer2005Prop.Default.PropPassword] = tbPw.Text;
            cObj.CustomerProperties[SqlServer2005Prop.Default.PropIntergrated] = cbInt.Checked.ToString();
        }

        #endregion
    }
}
